﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatHinhThuc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaHinhThuc();

            layTenHinhThuc();
        }
    }

    protected void layMaHinhThuc()
    {
        string maHinhThucURL = Request.QueryString["MaHinhThuc"];

        HinhThucBUS htBUS = new HinhThucBUS();

        string maHinhThuc = htBUS.layMaHinhThuc(maHinhThucURL);

        txtMaHinhThuc.Text = maHinhThuc;
    }

    protected void layTenHinhThuc()
    {
        string maHinhThucURL = Request.QueryString["MaHinhThuc"];

        HinhThucBUS htBUS = new HinhThucBUS();

        string tenHinhThuc = htBUS.layTenHinhThuc(maHinhThucURL);

        txtTenHinhThuc.Text = tenHinhThuc;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            HinhThuc htDTO = new HinhThuc();
            htDTO.MaHinhThuc = txtMaHinhThuc.Text.ToUpper();
            htDTO.TenHinhThuc = txtTenHinhThuc.Text.ToUpper();

            //Kiem tra rong
            if (htDTO.MaHinhThuc.ToString() == string.Empty)
            {
                Alert.Show("Ma hinh thuc khong duoc rong");
                return;
            }

            if (htDTO.TenHinhThuc.ToString() == string.Empty)
            {
                Alert.Show("Ten hinh thuc khong duoc rong");
                return;
            }

            //Sua
            if (htDTO.MaHinhThuc.ToString() != string.Empty && htDTO.TenHinhThuc.ToString() != string.Empty)
            {
                HinhThucBUS htBUS = new HinhThucBUS();

                string maHinhThucURL = Request.QueryString["MaHinhThuc"];

                htBUS.suaHinhThuc(htDTO, maHinhThucURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}